package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.domain.Admin;
import com.tanhua.manage.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {
    /**
     * 查询新注册用户、登陆次数
     * @param today 日志
     * @param type 操作类型：0101登陆  0102注册
     * @return
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log " +
            "WHERE log_time=#{today} AND TYPE=#{type}")
    Long queryNumsByType(@Param("today") String today, @Param("type") String type);

    /**
     * 查询活跃用户
     * @param today 日期
     * @return
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today}")
    Long queryNumsByDate(String today);

    /**
     * 查询次日留存
     * @param today 今天的日期
     * @param yesterday 昨天的日期
     * @return
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} AND TYPE='0101' AND user_id IN (\n" +
            "SELECT user_id FROM tb_log WHERE log_time=#{yesterday} AND TYPE='0102'\n" +
            ")")
    Long queryRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);
}
